<template>
  <div class="bg">
    <nav-com
      title="退款中"
      :showView='true'
      @back="backHandler()"
    ></nav-com>
    <div
      class="orders_list"
      style="padding-bottom:1vw"
    >
      <div
        class="order_box_title"
        style="display: flex; justify-content: space-between;  padding-top:5px;  margin-right: 10px;align-items: center;"
      >
        <div style="font-size:3.7vw; color:#000">商家已同意退款，请填写快递单号</div>
      </div>
      <div style="margin-left:3vw;margin:3vw">{{dataInfo.goods_title}}</div>
      <div style="margin-left:3vw;color:#808080;font-size:3.4vw">请在3天24小时内填写快递单号</div>
      <div style="background:#EEEEEE;margin:3vw;padding:3vw 2vw;font-size:3.6vw">
        <p><span style="font-weight:600">退货地址</span> <span style="float:right;color:#FE4B20">复制</span></p>
        <p>{{dataInfo.refund_addr}}</p>
        <p>{{dataInfo.phone}}</p>
      </div>
      <div
        class="button"
        v-if="dataInfo.express_no==null"
        @click="inputExpress"
      >填写快递单号</div>
      <div
        v-else
        style="background:#EEEEEE;margin:3vw;padding:3vw 2vw;font-size:3.6vw"
      >
        <p><span>{{dataInfo.express_no}}</span> <span
            style="float:right;color:#FE4B20"
            @click="inputExpress"
          >
            <van-icon name="edit" />修改
          </span></p>
      </div>
    </div>
    <div
      class="orders_list"
      style="min-height: 24vh;"
    >
      <div
        class="order_box_title"
        style="display: flex; justify-content: space-between;  padding-top:5px;  margin-right: 10px;align-items: center;"
      >
        <div style=" max-width: 250px; white-space: nowrap; text-overflow: ellipsis;overflow: hidden;">订单编号:{{dataInfo.aftersale_sn}}</div>
      </div>
      <div class="order_box">
        <img :src="dataInfo.goods_image">
        <div>
          <p>{{dataInfo.goods_title}}</p>
          <p style="font-size:12px;">数量：{{dataInfo.goods_num}}</p>
          <span>￥{{dataInfo.goods_price}}</span>
        </div>
      </div>
      <div class="order_bottom">商品总价：<span style="color:#FE4B20">￥{{dataInfo.goods_price}}</span></div>
    </div>
    <div
      class="orders_list"
      style="padding:3vw 0"
    >
      <div class="item_list">
        <div class="title">订单编号</div>
        <div>{{dataInfo.order_sn}}</div>
      </div>
      <div class="item_list">
        <div class="title">实际退款金额</div>
        <div>￥{{dataInfo.refund_fee}}</div>
      </div>
      <div class="item_list">
        <div class="title">退款优惠券</div>
        <div>￥{{dataInfo.coupon_fee}}</div>
      </div>
      <div class="item_list">
        <div class="title">退货原因</div>
        <div>{{dataInfo.user_reason}}</div>
      </div>
      <div class="item_list">
        <div class="title">申请时间</div>
        <div>{{dataInfo.createtime}}</div>
      </div>
    </div>
    <div class="bottom-button">
      <div class="cancel-btn" @click="cancelOrder">撤销申请</div>
    </div>
    <van-dialog
      v-model="show"
      title="快递单号"
      show-cancel-button
      @confirm='confirm'
      @cancel='show=false'
    >
      <van-field
        style="background:#EEEEEE;margin:3vw;width:92%"
        v-model="expressNo"
        placeholder="请填写快递单号"
      />
    </van-dialog>
  </div>
</template>

<script>
import navCom from "@/component/nav";
import { deleteAfterSalesDetail, inputExpressNo, cancelAfterSales } from "@/api/api";
import { Toast } from "vant";
export default {
  components: {
    navCom,
  },
  data() {
    return {
      show: false,
      dataInfo: {},
      expressNo: "",
      id: "",
    };
  },
  mounted() {
    this.id = this.$route.params.id;
    this.initData(this.id);
  },
  methods: {
    backHandler() {
      this.$router.go(-1);
    },
    initData(id) {
      deleteAfterSalesDetail({ id })
        .then((result) => {
          if (result.data.code == 1) {
            this.dataInfo = result.data.data;
            console.log(this.dataInfo);
          }
        })
        .catch((err) => {});
    },
    inputExpress() {
      this.show = true;
    },
    confirm() {
      inputExpressNo({ id: this.id, express_no: this.expressNo })
        .then((result) => {
          Toast(result.data.msg);
          this.initData(this.id)
        })
        .catch((err) => {});
    },
    cancelOrder(){
      cancelAfterSales({id:this.id}).then((result) => {
        Toast(result.data.msg)
        setTimeout(()=>{
          this.backHandler()
        },1000)
      }).catch((err) => {
        
      });
    },
  },
};
</script>

<style scoped>
.bottom-button{
  position: absolute;
  height: 6.5vh;
  background: #fff;
  /* border-top:1px solid #FE4B20; */
  bottom: 0;
  width: 100%;
  
}
.bottom-button .cancel-btn{
  width: 30vw;
  border: 1px solid #FE4B20;
  color: #FE4B20;
  height: 5vh;
  line-height: 5vh;
  margin: 0.75vh 3vh;
  border-radius: 2.5vh;
  text-align: center;
  float: right;
}
p {
  padding: 0;
  margin: 0;
}
.button {
  margin: 3vw;
  color: #fff;
  background: #fe4b20;
  height: 10vw;
  line-height: 10vw;
  border-radius: 5vw;
  text-align: center;
}
.item_list {
  display: flex;
  justify-content: space-between;
  margin: 0 2vw;
  font-size: 3.4vw;
  line-height: 7vw;
}
.item_list .title {
  color: #808080;
  min-width: 25vw;
}
.bg {
  background: #f2f3f7;
  min-height: 100vh;
  position: relative;
}
.orders_list {
  background: #fff;
  position: relative;
  margin: 4vw;
  border-radius: 10px;
}
.order_box_title {
  height: 9.3vw;
  font-size: 3.2vw;
  padding-left: 2.93vw;
  line-height: 9.3vw;
  color: #999;
  border-bottom: 1px solid #eeeeee;
}
.order_box {
  display: flex;
  border-bottom: 1px solid #eeeeee;
  padding-bottom: 10px;
}
.order_box img {
  width: 24vw;
  height: 24vw;
  padding-top: 3.3vw;
  padding-left: 2.93vw;
}
.order_box p {
  padding-left: 4vw;
  padding-top: 3.3vw;
  color: #333;
}
.order_box span {
  padding-left: 4vw;
  padding-top: 3vw;
  display: block;
  color: #ff0000;
  font-size: 18px;
}
.order_bottom {
  padding: 2vw 2.93vw;
  color: #808080;
  font-size: 13px;
  float: right;
}
</style>